home *** CD-ROM | disk | FTP | other *** search
- LSLinF - Least Squares Linear Function program
- ==============================================
-
- What it does :-
- ---------------
-
- given data points (x,y) or (x(1),x(2),y) etc. produce a curve fit of the form
-
- y = a(1)*f1(x(1)) + a(2)*f2(x(1)) + ...
-
- or
-
- y = a(1)*f1(x(1),x(2),...) + a(2)*f2(x(1),x(2),...) + ...
-
- and find the "best" values of a(1), a(2), etc. to minimise the error.
-
- The functions f1, f2 etc. can be any of the standard BASIC functions or
- user-defined functions in BASIC.
-
- Example 1. A simple starter
- ---------------------------
-
- Suppose your data looks like this
-
- x y
-
- 1 0.0
- 1.4 -1.2
- 2 -0.3
- 4 1.4
- 5.7 3.75
-
- and you would like a curve fit of the form
-
- y = a1 + a2*x + a3*tan(x/10) + a4*exp(x/10)
-
- the lines to enter in the program are
-
- 30DATA 4 : REM NUMBER OF FUNCTION TERMS
- 40DATA 1,X(1),TAN(X(1)/10),EXP(X(1)/10) :REM FUNCTION TERMS
- 50DATA 1 : REM NO. OF INDEPENDENT VARIABLES
- 60DATA X : REM INDEPENDENT VARIABLE TRANSFORMATION FUNCTION(S)
- 70DATA Y : REM DEPENDENT VARIABLE TRANSFORMATION FUNCTION
-
- and add your data at the end at say line 10000
-
- 10000 DATA 1 , 0.0
- 10010 DATA 1.4, -1.2
- 10020 DATA 2 , -0.3
- 10030 DATA 4 , 1.4
- 10040 DATA 5.7, 3.75
-
- The output looks like this
-
- LEAST SQUARE LINEAR FUNCTION FIT
- Y = A1*(1) + A2*(X(1)) + A3*(TAN(X(1)/10)) + A4*(EXP(X(1)/10))
-
- A1 = 138.800998
- A2 = -6.61692633
- A3 = 244.268219
- A4 = -143.588419
-
- RMS error = 3.35249813E-3
- MAX error = 5.95496874E-3
-
- Press <RETURN> to display a graph of the function
-
- Example 2. This shows the use of 2 independent variables
- --------------------------------------------------------
-
- Suppose your data looks like this:
-
- x(1) x(2) y
-
- 1.0 0.0 1.0
- 1.0 1.0 4.0
- 1.0 2.0 7.0
- 2.0 1.0 7.0
- 2.0 2.0 10.0
- 2.0 3.0 13.0
-
- This data actually represents the equation y = x(1)^2 + 3*x(2), so we can
- check if the program finds the right surface-fit. Your input data could
- look like this:
-
- 30DATA 5 : REM NUMBER OF FUNCTION TERMS
- 40DATA 1,X(1),X(1)^2,X(2),X(2)^2 : REM FUNCTION TERMS
- 50DATA 2 : REM NO. OF INDEPENDENT VARIABLES
- 60DATA X,X : REM INDEPENDENT VARIABLE TRANSFORMATION FUNCTION(S)
- 70DATA Y : REM DEPENDENT VARIABLE TRANSFORMATION FUNCTION
-
- We are specifying more function terms than are needed, since we already
- know the answer, but this will be a good test for the program.
- Add your data at the end at say line 10000
-
- 10000 DATA 1,0,1
- 10010 DATA 1,1,4
- 10020 DATA 1,2,7
- 10030 DATA 2,1,7
- 10040 DATA 2,2,10
- 10050 DATA 2,3,13
- 10060 DATA 3,0,9
-
- And your output should look like this:
-
- LEAST SQUARE LINEAR FUNCTION FIT
- Y = A1*(1) + A2*(X(1)) + A3*(X(1)^2) + A4*(X(2)) + A5*(X(2)^2)
-
- A1 = 1.27724239E-7
- A2 = -2.02096998E-7
- A3 = 1.00000005
- A4 = 3.00000005
- A5 = -1.11758709E-8
-
- RMS error = 1.92788031E-8
- MAX error = 3.35276127E-8
-
- Notice that the terms in 1, X(1) and X(2)^2 have coefficients approximately
- zero, since they are not needed. Notice also, that A3 and A4 are as
- expected.
-
-
- Example3. Transformation of x(1)
- --------------------------------
-
- Transformation modifies the value of x input points before curve-fitting
- takes place. For example, if you have very large values, you could
- divide them all by 1000 to avoid overflow, or you could, say, take the
- log of your data if you think the curve-fit might work better like this.
- Here is an example of some data which benefits from a transformation
-
- 30DATA 3 : REM NUMBER OF FUNCTION TERMS
- 40DATA X(1),X(1)^2,X(1)^3
- 50DATA 1 : REM NO. OF INDEPENDENT VARIABLES
- 60DATA SQR(X) : REM INDEPENDENT VARIABLE TRANSFORMATION FUNCTION(S)
- 70DATA Y : REM DEPENDENT VARIABLE TRANSFORMATION FUNCTION
-
- x is transformed to SQR(x).
-
- 10000DATA 1.000000,0.000000
- 10010DATA 0.975528,0.004834
- 10020DATA 0.904508,0.018164
- 10030DATA 0.793893,0.036729
- 10040DATA 0.654508,0.055902
- 10050DATA 0.500000,0.070711
- 10060DATA 0.345492,0.076942
- 10070DATA 0.206107,0.072084
- 10080DATA 0.095492,0.055902
- 10090DATA 0.024472,0.030521
- 10100DATA 0.000000,0.000000
-
- Yielding the result:
-
- LEAST SQUARE LINEAR FUNCTION FIT
- Y = A1*(X(1)) + A2*(X(1)^2) + A3*(X(1)^3)
-
- A1 = 0.199997935
- A2 = 6.92216755E-6
- A3 = -0.200004818
-
- RMS error = 1.8138212E-7
- MAX error = 3.0513911E-7
-
- Note that you must use the transformed value of x in the curve-fit equation,
- in this case
-
- Y = .2*SQR(X) + 6.9E-6*(SQR(X))^2 - .2*(SQR(X))^3
-
- = .2*SQR(X)*(1-X) (the equation we used to generate the data)
-
- As a comparison, you may like to remove the transformation and try this
- case again. You should find the RMS error is about 1000 times bigger.
- Transformation changes the shape of the graph, so, for example, if you
- were doing an exponential curve-fit and you used a transformation of
- LN(X), you would expect to see a straight line graph.
-
- Epilog
- ------
- We've used this program quite a lot at work (a technical engineering
- company) and it does work well. Sorry about the graphs! Version 4 is in
- the pipeline, with various extra features, including:
-
- Improved graphics
- Variable weighting on the input data
- Data validation
- Fewer bugs(!)
-
- This manual was written in about 2 hours, and probably looks like it. If
- you find LSLinF useful, or have any further queries, you can get in touch
- with us:
-
- AUTHOR: COLLABORATOR:
-
- Alan Linton Lorcan Mongey
- 16 Victoria Road 56 Salisbury Court
- Belfast BT4 1QU Belfast BT7 1DD
-
- BBS: (id = lorcan)
- The World of Cryton (0749 670030)
- CIX (081 390 1244)
- Arcade (081 654 2212)
-